package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.bean.BillsTO;
import com.ecable.bean.ConnectionTO;
import com.ecable.daoImpl.ConnectionDaoImpl;
import com.ecable.util.UtilConstants;

public class BillPayAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8739119206017332679L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		RequestDispatcher rd = null;

		boolean flag = false;
		String path = "";
		ConnectionTO conn = new ConnectionTO();
		BillsTO bill = new BillsTO();

		bill.setBankname(request.getParameter("BankName"));
		bill.setAmount(Float.parseFloat(request.getParameter("Amount")));
		bill.setBankdd(request.getParameter("bankdd"));
		bill.setUserid(Integer.parseInt(request.getParameter("userid")));
		bill.setConnid(Integer.parseInt(request.getParameter("connid")));
		System.out.println("at REGCONNECTIOM.JSP"
				+ request.getParameter("userid"));
		/*
		 * Map map=request.getParameterMap(); try { BeanUtils.populate(pack,
		 * map); } catch (IllegalAccessException e1) { // TODO Auto-generated
		 * catch block e1.printStackTrace(); } catch (InvocationTargetException
		 * e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
		 */
		try {
			flag = new ConnectionDaoImpl().payBill(bill);

			if (flag) {

				request.setAttribute("status", UtilConstants._BILL_PAY);

				path = UtilConstants._Coustomer_Home;

			} else {

				request.setAttribute("status", UtilConstants._Bill_PAID_FAILED);

				path = UtilConstants._Coustomer_Home;

			}

		} catch (Exception e) {
			e.printStackTrace();

			request.setAttribute("status", UtilConstants._Bill_PAID_FAILED);

			path = UtilConstants._Coustomer_Home;

		}

		rd = request.getRequestDispatcher(path);

		rd.forward(request, response);

	}

}
